package com.book.lizhi.ui;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.TextView;

import com.book.lizhi.AppApplication;
import com.book.lizhi.BaseActivity;
import com.book.lizhi.R;
import com.book.lizhi.model.BookModel;
import com.book.lizhi.ui.fragment.ChapterFragment;

public class ChapterActivity extends BaseActivity {
	private TextView mBookName;
	private BookModel mBookModel;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_chapter);
		mBookName = (TextView) findViewById(R.id.chapter_book_name);
		mBookModel = AppApplication.instance.currentBookModel;
		mBookName.setText(mBookModel.name);
		
		Toolbar toolbar = (Toolbar) findViewById(R.id.toobar);
		setSupportActionBar(toolbar);

		ActionBar actionBar = getSupportActionBar();
		actionBar.setDisplayHomeAsUpEnabled(true);
		actionBar.setDisplayShowHomeEnabled(false);
		actionBar.setTitle("目录");

		FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
		transaction.add(R.id.chapter_container, new ChapterFragment(), "chapter");
		transaction.commitAllowingStateLoss();
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if (item.getItemId() == android.R.id.home) {
			finish();
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
